package com.ruoyi.appreciate.competition.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.appreciate.competition.domain.Competition;
import com.ruoyi.appreciate.competition.service.ICompetitionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 书法赛事Controller
 * 
 * @author duanxinli
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/competition/competition")
public class CompetitionController extends BaseController
{
    @Autowired
    private ICompetitionService competitionService;

    /**
     * 查询书法赛事列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(Competition competition)
    {
        startPage();
        List<Competition> list = competitionService.selectCompetitionList(competition);
        return getDataTable(list);
    }

    /**
     * 导出书法赛事列表
     */
    @PreAuthorize("@ss.hasPermi('competition:competition:export')")
    @Log(title = "书法赛事", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Competition competition)
    {
        List<Competition> list = competitionService.selectCompetitionList(competition);
        ExcelUtil<Competition> util = new ExcelUtil<Competition>(Competition.class);
        util.exportExcel(response, list, "书法赛事数据");
    }

    /**
     * 获取书法赛事详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(competitionService.selectCompetitionById(id));
    }

    /**
     * 新增书法赛事
     */
    @PreAuthorize("@ss.hasPermi('competition:competition:add')")
    @Log(title = "书法赛事", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Competition competition)
    {
        return toAjax(competitionService.insertCompetition(competition));
    }

    /**
     * 修改书法赛事
     */
    @PreAuthorize("@ss.hasPermi('competition:competition:edit')")
    @Log(title = "书法赛事", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Competition competition)
    {
        return toAjax(competitionService.updateCompetition(competition));
    }

    /**
     * 删除书法赛事
     */
    @PreAuthorize("@ss.hasPermi('competition:competition:remove')")
    @Log(title = "书法赛事", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(competitionService.deleteCompetitionByIds(ids));
    }

}
